//
//  MainViewController.m
//  JYJTextApplication
//
//  Created by 冀永金 on 16/8/26.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "MainViewController.h"
#import "BaseNavigationContoller.h"
#import "JYJVCOfDiscover.h"
#import "JYJVCOfLoveListen.h"
#import "JYJVCOfSocialContact.h"
#import "JYJVCOfMine.h"
#import "JYJVCOfSet.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.viewControllers = [self createTabBarContollers];
        self.tabBar.barTintColor = [UIColor redColor];
        [[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
    }
    return self;
}
- (NSArray<UIViewController *> *)createTabBarContollers {
    NSMutableArray *marrOfVCs = [NSMutableArray array];
    JYJVCOfDiscover *vcOfDiscover = [[JYJVCOfDiscover alloc]init];
    BaseNavigationContoller *itemOfDiscover = [[BaseNavigationContoller alloc]initWithRootViewController:vcOfDiscover];
    itemOfDiscover.tabBarItem.image = [[UIImage imageNamed:@"menu_icon_1_1"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemOfDiscover.tabBarItem.selectedImage = [[UIImage imageNamed:@"menu_icon_1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemOfDiscover.tabBarItem.title = @"发现";
    [marrOfVCs addObject:itemOfDiscover];
    JYJVCOfLoveListen *vcOfListen = [[JYJVCOfLoveListen alloc]init];
    BaseNavigationContoller *itemOfLoveListen = [[BaseNavigationContoller alloc]initWithRootViewController:vcOfListen];
    itemOfLoveListen.tabBarItem.image = [[UIImage imageNamed:@"menu_icon_3_1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemOfLoveListen.tabBarItem.selectedImage = [[UIImage imageNamed:@"menu_icon_3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemOfLoveListen.tabBarItem.title = @"爱听";
    [marrOfVCs addObject:itemOfLoveListen];
    JYJVCOfSocialContact *vcOfSocial = [[JYJVCOfSocialContact alloc]init];
    BaseNavigationContoller *itemOfSocial = [[BaseNavigationContoller alloc]initWithRootViewController:vcOfSocial];
    itemOfSocial.tabBarItem.image = [[UIImage imageNamed:@"menu_icon_2_1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
   itemOfSocial.tabBarItem.selectedImage = [[UIImage imageNamed:@"menu_icon_2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemOfSocial.tabBarItem.title = @"社交";
    [marrOfVCs addObject:itemOfSocial];
    //判断是否登录，有登陆状态判断
    //获取userDeafaults
    NSUserDefaults *usersDeafaults = [NSUserDefaults standardUserDefaults];
    NSString *name = [usersDeafaults objectForKey:@"userName"];
    NSDictionary *dic = [usersDeafaults objectForKey:@"info"];
    if (name == nil) {
        JYJVCOfMine *vcOfMine = [[JYJVCOfMine alloc]init];
        BaseNavigationContoller *itemOfMine = [[BaseNavigationContoller alloc]initWithRootViewController:vcOfMine];
        itemOfMine.tabBarItem.image = [[UIImage imageNamed:@"menu_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        itemOfMine.tabBarItem.selectedImage = [[UIImage imageNamed:@"menu_icon_0"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        itemOfMine.tabBarItem.title = @"我的";
        
        [marrOfVCs addObject:itemOfMine];
        
        
    }else {
        JYJVCOfSet *set = [[JYJVCOfSet alloc]init];
        set.dic = dic;
        BaseNavigationContoller *itemOfMine = [[BaseNavigationContoller alloc]initWithRootViewController:set];
        itemOfMine.tabBarItem.image = [[UIImage imageNamed:@"menu_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        itemOfMine.tabBarItem.selectedImage = [[UIImage imageNamed:@"menu_icon_0"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        itemOfMine.tabBarItem.title = @"我的";
        [marrOfVCs addObject:itemOfMine];

    }
    return marrOfVCs;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
